package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.Appointment;
import cn.hl.sfzy.entity.Consult;
import cn.hl.sfzy.entity.Specialty;
import cn.hl.sfzy.entity.User;
import cn.hl.sfzy.mapper.AppointmentMapper;
import cn.hl.sfzy.mapper.ConsultMapper;
import cn.hl.sfzy.mapper.SpecialtyMapper;
import cn.hl.sfzy.mapper.UserMapper;
import cn.hl.sfzy.service.AppointmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AppointmentServiceImpl
 * @Description TODO
 * @Author LiuYao
 * @Date 2024年10月24日 10:55
 * @Version 1.0
 */
@Service
public class AppointmentServiceImpl implements AppointmentService {
    @Autowired
    private AppointmentMapper appointmentMapper;
    @Autowired
    private ConsultMapper consultMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private SpecialtyMapper specialtyMapper;
    @Override
    public int remove(Long id) {
        return appointmentMapper.delete(id);
    }

    @Override
    public PageInfo findByPage(Integer pageNum, Integer pageSize, Appointment appointment) {
        PageHelper.startPage(pageNum,pageSize);
        List<Appointment> list= appointmentMapper.select(appointment);
        for(Appointment at : list){
            Consult consult = consultMapper.selectById(at.getConsult_id());
            User user=userMapper.selectById(at.getUser_id());
            Specialty specialty=specialtyMapper.selectById(at.getType_Id());
            at.setConsult(consult);
            at.setUser(user);
            at.setSpecialty(specialty);
        }
        PageInfo<Appointment> pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<Appointment> find(Appointment appointment) {
        return appointmentMapper.select(appointment);
    }

    @Override
    public int deleteByUserid(Long user_id) {
        int i = appointmentMapper.deleteByUserid(user_id);
        return i;
    }
}
